package concurrent.mysynchronized;

/**
 * @package concurrent.mysynchronized
 * @Class SynchronizedClassClass
 * @Description TODO
 * @Author zhangxinhua
 * @Date 20-1-9 下午1:43
 */
public class SynchronizedClassClass implements Runnable {
    static SynchronizedClassClass instance1 = new SynchronizedClassClass();
    static SynchronizedClassClass instance2 = new SynchronizedClassClass();
    @Override
    public void run() {
        method();
    }


    public  void method() {
        synchronized (SynchronizedClassClass.class) {
            System.out.println("我是对象锁的方法修饰符形式，我叫"+Thread.currentThread().getName());
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"执行完毕");
        }
    }

    public static void main(String[] args) {

        Thread t1 = new Thread(instance1);
        Thread t2 = new Thread(instance2);
        t1.start();
        t2.start();
        while (t1.isAlive() || t2.isAlive()) {

        }
        System.out.println("finished:");
    }
}
